﻿using SimpleServiceBus.Bus.MessageManagement.MessageHandling;
using SimpleServiceBus.Bus.Pipeline;
using SimpleServiceBus.Messages.Management.Monitoring;

namespace SimpleServiceBus.EndpointManagement.Server.MessageHandlers
{
    public class EndpointStatusMessageHandler : MonitorServiceMessageHandler<EndpointStatusUpdateNotification>,
                                                IMessageHandler<EndpointOnlineNotification>,
                                                IMessageHandler<EndpointOfflineNotification>,
                                                IMessageHandler<EndpointErrorNotification>
    {

        #region IMessageHandler<EndpointOfflineNotification> Members

        public void Handle(EndpointOfflineNotification message, IMessageContext context)
        {
            var svc = GetEndpointMonitorService(context);
            if (svc != null)
                svc.UpdateEndpointStatus(message);
        }

        #endregion

        #region IMessageHandler<EndpointOnlineNotification> Members

        public void Handle(EndpointOnlineNotification message,IMessageContext context)
        {
            var svc = GetEndpointMonitorService(context);
            if (svc != null)
                svc.UpdateEndpointStatus(message);
        }

        #endregion

        public void Handle(EndpointErrorNotification message, IMessageContext context)
        {
            var svc = GetEndpointMonitorService(context);
            if (svc != null)
                svc.UpdateEndpointStatus(message);
        }

        public override void Handle(EndpointStatusUpdateNotification message,IMessageContext context)
        {
            var svc = GetEndpointMonitorService(context);
            if (svc != null)
                svc.UpdateEndpointStatus(message);
        }
    }
}